package com.whnk.web.controller.model;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.whnk.common.annotation.Log;
import com.whnk.common.base.AjaxResult;
import com.whnk.common.enums.BusinessType;
import com.whnk.framework.web.base.BaseController;
import com.whnk.framework.web.page.TableDataInfo;
import com.whnk.model.domain.TCustInfo;
import com.whnk.model.service.ITCustInfoService;

/**
 * 客户 信息操作处理
 * 
 * @author whwhnk
 * @date 2021-05-28
 */
@Controller
@RequestMapping("/model/tCustInfo")
public class TCustInfoController extends BaseController
{
    private String prefix = "model/tCustInfo";
	
	@Autowired
	private ITCustInfoService tCustInfoService;
	
	@RequiresPermissions("model:tCustInfo:view")
	@GetMapping()
	public String tCustInfo()
	{
	    return prefix + "/tCustInfo";
	}
	
	/**
	 * 查询客户列表
	 */
	@RequiresPermissions("model:tCustInfo:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(TCustInfo tCustInfo)
	{
		startPage();
        List<TCustInfo> list = tCustInfoService.selectTCustInfoList(tCustInfo);
		return getDataTable(list);
	}
	
	/**
	 * 新增客户
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存客户
	 */
	@RequiresPermissions("model:tCustInfo:add")
	@Log(title = "客户", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(TCustInfo tCustInfo)
	{		
		return toAjax(tCustInfoService.insertTCustInfo(tCustInfo));
	}

	/**
	 * 修改客户
	 */
	@GetMapping("/edit/{iD}")
	public String edit(@PathVariable("iD") String iD, ModelMap mmap)
	{
		TCustInfo tCustInfo = tCustInfoService.selectTCustInfoById(iD);
		mmap.put("tCustInfo", tCustInfo);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存客户
	 */
	@RequiresPermissions("model:tCustInfo:edit")
	@Log(title = "客户", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(TCustInfo tCustInfo)
	{		
		return toAjax(tCustInfoService.updateTCustInfo(tCustInfo));
	}
	
	/**
	 * 删除客户
	 */
	@RequiresPermissions("model:tCustInfo:remove")
	@Log(title = "客户", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(tCustInfoService.deleteTCustInfoByIds(ids));
	}
	
}
